package admin

import (
	"context"

	"server/internal/svc"
	"server/internal/types"
	"server/models"
	"server/utils"

	"github.com/zeromicro/go-zero/core/logx"
)

type RoleSelectLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoleSelectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleSelectLogic {
	return &RoleSelectLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleSelectLogic) RoleSelect() (resp []types.SelectIntOptions, err error) {
	tx := utils.Db.Model(&models.AdminRole{}).Order("id desc")

	datas := make([]models.AdminRole, 0)
	utils.TxFind(tx, &datas)

	for _, v := range datas {
		resp = append(resp, types.SelectIntOptions{
			Value: v.ID,
			Label: v.Name,
		})
	}
	return resp, nil
}
